package com.lili.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SwaggerConfig {

    /**
     * 管理员
     * @return
     */
    @Bean
    public Docket adminDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .groupName("admin")
                .enable(true)//为true可以访问 false不能访问
                .select()
                //.apis(RequestHandlerSelectors.basePackage())
                .paths(PathSelectors.regex("/admin/.*"))
                .build();
    }

    /**
     * openfeign接口使用
     * @return
     */
    @Bean
    public Docket apiDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .enable(true)//为true可以访问 false不能访问
                .groupName("api")
                .select()
                //.apis(RequestHandlerSelectors.basePackage())
                .paths(PathSelectors.regex("/api/.*"))
                .build();
    }


    /**
     * 商家
     * @return
     */
    @Bean
    public Docket sellerDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .enable(true)//为true可以访问 false不能访问
                .groupName("seller")
                .select()
                //.apis(RequestHandlerSelectors.basePackage())
                .paths(PathSelectors.regex("/sell/.*"))
                .build();
    }

    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("天行健")
                .description("君子以自强不息")
                .contact(new Contact("丽丽少铺", "http://localhost", "tianwenle@aliyun.com"))
                .version("v1.0")
                .build();
    }
}